fn map_roman_to_int(s: char) -> i32 {
    match s {
        'I' => 1,
        'V' => 5,
        'X' => 10,
        'L' => 50,
        'C' => 100,
        'D' => 500,
        'M' => 1000,
        _ => 0,
    }
}

pub fn roman_to_int(s: String) -> i32 {
    let mut sum = 0;
    let chars: Vec<char> = s.chars().collect();
    let len = chars.len();

    for i in 0..len {
        let c = chars[i];
        let n = map_roman_to_int(c);
        if i < len - 1 {
            let next_c = chars[i + 1];
            let next_n = map_roman_to_int(next_c);
            if next_n > n {
                sum -= n;
            } else {
                sum += n;
            }
        } else {
            sum += n;
        }
    }

    return sum;
}
